#include "ProcessImageTcpClient.h"

ProcessImageTcpClient::ProcessImageTcpClient(){

	width = IMG_WIDTH;
	height = IMG_HEIGHT;

	port = 6667;
	ip = "192.168.0.2";
	init();

}
ProcessImageTcpClient::~ProcessImageTcpClient(){

	socketMat.socketDisconnect();
}

void ProcessImageTcpClient::init(){
	if (socketMat.socketConnect(ip, port) < 0)
	{
		cout<< "connect error\n";
	}
	struct infohead head;
	head.detectType =1;
	head.width =IMG_WIDTH;
	head.height =IMG_HEIGHT;
	head.packageNum =PACKAGE_NUM;
	if(socketMat.transmit(head) != 0)
	{
		cout<< "transmit head error\n";
	}
	cout<< "tcpClient init complete\n";

}



int ProcessImageTcpClient::process(Mat image, string &res) {

	if (image.empty())
			return -1;

	cv::resize(image, image, cv::Size(width, height));		
	socketMat.transmit(image);
	res = socketMat.receive();
	//cout<<"in client res: "<< res <<endl;
	return 0;


 }
